﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Core;
using EPiServer.SpecializedProperties;

namespace EPiBoost.Core.Extensions
{
	public static class LinkItemCollectionExtensions
	{
		public static PageDataCollection GetAsPageData(this LinkItemCollection self)
		{
			return self.GetAsPageData(null);
		}


		/// <summary>
		/// Gets the LinkItemCollection as a PageDataCollection
		/// Removes any links that are not PageData
		/// </summary>
		/// <param name="self">LinkItemCollection</param>
		/// <returns>PageDataCollection</returns>
		public static PageDataCollection GetAsPageData(this LinkItemCollection self, string languageBranch)
		{
			PageDataCollection pdc = new PageDataCollection();
			if (self != null)
			{
				foreach (LinkItem linkItem in self)
				{
					PageData pData = null;
					if (linkItem.TryParseToPageData(out pData, languageBranch) && pData.IsDeleted == false)
					{
						pdc.Add(pData);
					}
				}
			}
			return pdc;
		}
	}
}
